package com.muyu.danmo.controller;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.danmo.domain.DanmoInformationVideo;
import com.muyu.danmo.service.IDanmoInformationVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 个人信息视频集Controller
 * 
 * @author yangle
 * @date 2024-12-18
 */
@RestController
@RequestMapping("/danmoInformationVideo")
public class DanmoInformationVideoController extends BaseController {
    @Autowired
    private IDanmoInformationVideoService danmoInformationVideoService;

    /**
     * 查询个人信息视频集列表
     */
//    @RequiresPermissions("system:danmoInformationVideo:list")
    @GetMapping("/list")
    public Result<TableDataInfo<DanmoInformationVideo>> list(DanmoInformationVideo danmoInformationVideo) {
        startPage();
        List<DanmoInformationVideo> list = danmoInformationVideoService.selectDanmoInformationVideoList(danmoInformationVideo);
        return getDataTable(list);
    }

    /**
     * 导出个人信息视频集列表
     */
//    @RequiresPermissions("system:danmoInformationVideo:export")
    @Log(title = "个人信息视频集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoInformationVideo danmoInformationVideo) {
        List<DanmoInformationVideo> list = danmoInformationVideoService.selectDanmoInformationVideoList(danmoInformationVideo);
        ExcelUtil<DanmoInformationVideo> util = new ExcelUtil<DanmoInformationVideo>(DanmoInformationVideo.class);
        util.exportExcel(response, list, "个人信息视频集数据");
    }

    /**
     * 获取个人信息视频集详细信息
     */
//    @RequiresPermissions("system:danmoInformationVideo:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return success(danmoInformationVideoService.selectDanmoInformationVideoById(id));
    }

    /**
     * 新增个人信息视频集
     */
//    @RequiresPermissions("system:danmoInformationVideo:add")
    @Log(title = "个人信息视频集", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result add(@RequestBody DanmoInformationVideo danmoInformationVideo) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser == null) {
            return Result.notLoggedIn("请登录");
        }
        danmoInformationVideo.setUserId(loginUser.getUserid());
        return danmoInformationVideoService.insertDanmoInformationVideo(danmoInformationVideo);
    }

    /**
     * 修改个人信息视频集
     */
//    @RequiresPermissions("system:danmoInformationVideo:edit")
    @Log(title = "个人信息视频集", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoInformationVideo danmoInformationVideo) {
        return danmoInformationVideoService.updateDanmoInformationVideo(danmoInformationVideo);
    }

    /**
     * 删除个人信息视频集
     */
//    @RequiresPermissions("system:danmoInformationVideo:remove")
    @Log(title = "个人信息视频集", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids) {
        return danmoInformationVideoService.deleteDanmoInformationVideoByIds(ids);
    }

    /**
     * 查看自己的视频
     */
    @PostMapping("/viewDetails")
    public Result getInfo(@RequestBody DanmoInformationVideo danmoInformationVideo) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser == null) {
            return Result.notLoggedIn("请登录");
        }
        danmoInformationVideo.setUserId(loginUser.getUserid());
        List<DanmoInformationVideo> danmoInformationVideos = danmoInformationVideoService.selectDanmoInformationVideoList(danmoInformationVideo);
        return  Result.success(danmoInformationVideos);
    }
}